//
// Created by lanlu on 2025/8/4.
//
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

class Solution {
public:
    vector<vector<int> > threeSum(vector<int> &nums)
    {
        // 最终结果是 二维数组 数组的每个元素是三元组
        vector<vector<int> > result;
        for (int i = 0; i < nums.size(); i++)
        {
            for (int j = i + 1; j < nums.size(); j++)
            {
                for (int k = j + 1; k < nums.size(); k++)
                {
                    if (nums[i] + nums[j] + nums[k] == 0)
                    {
                        vector<int> arr = {nums[i], nums[j], nums[k]};
                        // 去重 先排序
                        sort(arr.begin(), arr.end());
                        bool isExists = false;
                        for (vector<int> v : result)
                        {
                            if (v[0]==arr[0] && v[1]==arr[1] && v[2]==arr[2])
                            {
                                isExists = true;
                                break;
                            }
                        }
                        if (!isExists)
                        {
                            result.push_back(arr);
                        }
                    }
                }
            }
        }

        return result;
    }
};

int main()
{
    Solution s;
    vector<int> nums = {-1, 0, 1, 2, -1, -4};
    vector<vector<int> > result = s.threeSum(nums);
    for (vector<int> v : result)
    {
        for (int i : v)
        {
            cout << i << " ";
        }
        cout << endl;
    }
}